package org.gpp.proj1.camera.action;

import junit.framework.TestCase;

import org.gpp.proj1.camera.CameraDirector;

import com.jme.renderer.Camera;
import com.jme.scene.CameraNode;
import com.jme.scene.Node;
import com.jme.system.DisplaySystem;

public class SetFocusActionTest extends TestCase {

	/*
	 * Test method for 'org.gpp.proj1.camera.action.SetFocusAction.SetFocusAction(CameraDirector, Node)'
	 */
	public void testSetFocusAction() {
		Camera cam = DisplaySystem.getDisplaySystem().getRenderer().getCamera();		
		CameraNode node = new CameraNode( "CamNode", cam );
		
		// Cannot create action with null director
		try {
			new SetFocusAction( null, null );	
		} catch( AssertionError e ) {
			// expected error
		}
		
		// Cannot create action with null target
		try {
			new SetFocusAction( new CameraDirector( node ), null );	
		} catch( AssertionError e ) {
			// expected error
		}

		// Valid construct
		try {
			new SetFocusAction( new CameraDirector( node ), new Node( "target" ) );	
		} catch( AssertionError e ) {
			// expected error
		}
	}

	/*
	 * Test method for 'org.gpp.proj1.camera.action.SetFocusAction.updateAction(float, CameraNode)'
	 */
	public void testUpdateAction() {
		Camera cam = DisplaySystem.getDisplaySystem().getRenderer().createCamera( 0, 0 );		
		CameraNode node = new CameraNode( "CamNode", cam );
		
		CameraDirector director = new CameraDirector( node );
		Node target = new Node( "target" );
		
		SetFocusAction action = new SetFocusAction( director, target );
		
		assertNull( director.getFocusedObject() );
		
		action.updateAction( 0.0f, node );
		
		assertNotNull( director.getFocusedObject() );
		assertEquals( director.getFocusedObject(), target );
	}

	/*
	 * Test method for 'org.gpp.proj1.camera.action.SetFocusAction.isFinished()'
	 */
	public void testIsFinished() {
		Camera cam = DisplaySystem.getDisplaySystem().getRenderer().getCamera();		
		CameraNode node = new CameraNode( "CamNode", cam );
		
		SetFocusAction action = new SetFocusAction( new CameraDirector( node ), new Node( "target" ) );
		
		assertFalse( action.isFinished() );
		
		action.updateAction( 0.0f, node );
		
		assertTrue( action.isFinished() );
	}

}
